﻿using Enterprise_Set.API.Application.Commands.Week1.Log_CR;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Set.API.Controllers.Week1
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserLogController : ControllerBase
    {
        public UserLogController(IMediator mediator, ILogger<UserLogController> Logger)
        {
            Mediator = mediator;
            this.Logger = Logger;
        }

        public IMediator Mediator { get; set; }
        public ILogger<UserLogController> Logger { get; set; }
        /// <summary>
        /// 添加日志
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("AddUserLogData")]
        public async Task<Result> AddUserLogData(AddLogCommand cmd)
        {
            try
            {
                Logger.LogInformation("添加用户行为日志");
                return await Mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                Logger.LogError("用户行为日志添加失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 显示日志表数据
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet("ShowUserLogData")]
        public async Task<Result> ShowUserLogData()
        {
            try
            {
                Logger.LogInformation("显示日志表数据成功");
                return await Mediator.Send(new ShowUserLogCommand());
            }
            catch (Exception ex)
            {
                Logger.LogError("显示日志表数据失败" + ex.Message);
                throw;
            }
        }
    }
}
